package com.geek.javase.ExtendsWork;

/**
 * @author chenshupeng
 * @date 2025/9/2
 * @desc TODO
 **/

public class Person {
    private String name;
    private int age;
    private boolean gender;
    public Person partner;

    public Person() {
    }

    public Person(String name, int age, boolean gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     * @return gender
     */
    public boolean isGender() {
        return gender;
    }

    /**
     * 设置
     * @param gender
     */
    public void setGender(boolean gender) {
        this.gender = gender;
    }

    /**
     * 获取
     * @return partner
     */
    public Person getPartner() {
        return partner;
    }

    /**
     * 设置
     * @param partner
     */
    public void setPartner(Person partner) {
        this.partner = partner;
    }

    public String toString() {
        return "Person{name = " + name + ", age = " + age + ", gender = " + gender + ", partner = " + partner + "}";
    }
    public boolean marry(Person p)
    {
        if(p.gender==this.gender)
        {
            System.out.println("同性不能结婚");
            return false;
        }

        boolean a=(p.gender&&p.age<24)||(!p.gender&&p.age<22);
        boolean b=(this.gender&&this.age<24)||(!this.gender&&this.age<22);

        if(a||b){
            System.out.println("存在未达到结婚年龄");
            return false;
        }
        if(p.partner!=null||this.partner!=null)
        {
            System.out.println("一方已婚");
            return false;
        }
        System.out.println(this.name+"和"+p.name+"可以结婚，恭喜");
        this.partner=p;
        p.partner=this;
        return true;
    }
}
